package com.tenglong.teacher.data.resultInfo;


import com.netease.nimlib.sdk.auth.LoginInfo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class DataState implements Serializable {
    private static DataState mState = new DataState();

    private DataState() {
    }

    public static DataState getInstance() {
        return mState;
    }

    private String tempImtoken;
    private LoginInfo WYLoginInfo;
    private List<ClientUserInfo> userInfos;
    private boolean loginState = false;
    private boolean correlationAnswerIsClassNumChange = false;
    public int organizationIndex = 0;

    public int getOrganizationIndex() {
        return organizationIndex;
    }

    public void setOrganizationIndex(int organizationIndex) {
        this.organizationIndex = organizationIndex;
    }

    public List<ClientUserInfo> getUserInfos() {
        return userInfos;
    }

    public void setUserInfos(List<ClientUserInfo> userInfos) {
        this.userInfos = userInfos;
    }

    public String getTempImtoken() {
        return tempImtoken;
    }

    public void setTempImtoken(String tempImtoken) {
        this.tempImtoken = tempImtoken;
    }

    public LoginInfo getWYLoginInfo() {
        return WYLoginInfo;
    }

    public void setWYLoginInfo(LoginInfo WYLoginInfo) {
        this.WYLoginInfo = WYLoginInfo;
    }

    public boolean isLoginState() {
        return loginState;
    }

    public void setLoginState(boolean loginState) {
        this.loginState = loginState;
    }

    public boolean isCorrelationAnswerIsClassNumChange() {
        return correlationAnswerIsClassNumChange;
    }

    public void setCorrelationAnswerIsClassNumChange(boolean correlationAnswerIsClassNumChange) {
        this.correlationAnswerIsClassNumChange = correlationAnswerIsClassNumChange;
    }

    public ClientUserInfo getUserInfo() {
        if (userInfos == null || userInfos.size() == 0 || userInfos.size() <= organizationIndex) {
            return new ClientUserInfo();
        } else {
            return userInfos.get(organizationIndex);
        }
    }

    public ClientUserInfo getUserInfo(int position) {
        if (userInfos == null || userInfos.size() == 0 || userInfos.size() <= position) {
            return new ClientUserInfo();
        } else {
            return userInfos.get(position);
        }
    }

    public void appLogin(List<ClientUserInfo> userInfos) {
        this.userInfos = userInfos;
        this.loginState = true;
    }

    public void resetLoginInfo(ClientUserInfo userInfo) {
        if (userInfos == null) {
            userInfos = new ArrayList<>();
            userInfos.add(userInfo);
            organizationIndex = userInfos.size() - 1;
        } else {
            if (userInfos.size() == 0 || userInfos.size() <= organizationIndex) {
                userInfos.add(userInfo);
                organizationIndex = userInfos.size() - 1;
            } else {
                userInfos.set(organizationIndex, userInfo);
            }
        }
    }

    public void appExit() {
        if (userInfos != null) {
            userInfos.clear();
            userInfos = null;
        }
        this.organizationIndex = 0;
        this.loginState = false;
        this.WYLoginInfo = null;
        this.tempImtoken = null;
        correlationAnswerIsClassNumChange = false;
    }
}
